<template>
	<view>
		<!-- uview组件简单二次封装 -->
		<u-navbar :title="title" :bgColor="bgColor" :leftIconColor="leftIconColor" :titleStyle="titleStyle"
			:rightText="rightText" @leftClick="leftClick" @rightClick="clickRight" placeholder fixed  :autoBack="false"></u-navbar>
	</view>

</template>

<script>
	export default {
		name: "navbar",
		// 根据不同项目导航栏的主题色来设置默认样式
		props: {
			title: {
				type: String,
				default: ''
			},
			bgColor: {
				type: String,
				default: '#ffffff'
			},
			leftIconColor: {
				type: String,
				default: '#666666'
			},
			rightText: {
				type: String,
				default: ''
			},
			titleStyle: {
				type: Object,
				default: function() {
					return {
						color: '#3D3D3D'
					}
				}
			},
		},
		data() {
			return {
				status:1
			};
		},
		created() {
			// console.log('调用自定义导航栏组件')
		},
		methods:{
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if ( canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url:'/pages/index/cloudCatIndex'
					})
				}
			},
			// 触发父组件方法 传递数据
			clickRight() {
				 this.$emit('rightClick');
			},
		}
	}
</script>

<style scoped>

</style>